import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class MonIpDAO {
	private Connection conn;	
	private PreparedStatement ps;
	private ResultSet rs;	
	
	public IP ipSearch(String sip,long ip){
		String sql = "SELECT * FROM moniplib WHERE value>=? ORDER BY value";
		try {
			IP result = new IP();
			conn = new DBUtil().getConn();
			ps =  conn.prepareStatement(sql);
			ps.setLong(1,ip);
			rs = ps.executeQuery();	
			
			if(rs.next()){
				result.setIpAddr(sip);
				result.setCountry(rs.getString("country"));
				result.setProvince(rs.getString("province"));
				result.setCity(rs.getString("city"));
				result.setValue(rs.getLong("value"));
			}	
			ps.close();
			conn.close();
			return result;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
